package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.FollowMapper;
import com.hu.zhcc.shiro.dao.HMemberofthefileMapper;
import com.hu.zhcc.shiro.dao.TherapyMapper;
import com.hu.zhcc.shiro.entity.bo.Follow;
import com.hu.zhcc.shiro.entity.bo.HMemberofthefile;
import com.hu.zhcc.shiro.entity.bo.Therapy;
import com.hu.zhcc.shiro.entity.vo.FollowVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FollowServiceImpl implements FollowService{

    @Autowired
    private FollowMapper followMapper;
    @Autowired
    private HMemberofthefileMapper hMemberofthefileMapper;
    @Autowired
    private TherapyMapper therapyMapper;

    @Override
    public boolean AddFollow(Follow follow) {
            return followMapper.insert(follow)>0;
    }
    //分页查询
    @Override
    public PageInfo<Follow> pageQuery(FollowVO followVO) {
        PageHelper.startPage(followVO.getPageNum(),followVO.getPageSize());
        List<Follow> byCondition = followMapper.findByCondition(followVO.getQueryString());
        PageInfo<Follow> checkItemPageInfo = new PageInfo<>(byCondition);
        return checkItemPageInfo;
    }

    @Override
    public boolean updateFollow(Follow follow) {
        if(follow.getResult().equals("OK")){
            follow.setState(0);
        }else{
            Therapy bynumber = therapyMapper.findBynumber(follow.getFilenumber());
            bynumber.setState(1);
            therapyMapper.updateByPrimaryKey(bynumber);
        }
        return followMapper.updateByPrimaryKey(follow)>0;
    }

    @Override
    public boolean removeFollow(Short id) {
        return followMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public HMemberofthefile findbynumber(String number) {
        System.out.println(number);
        return hMemberofthefileMapper.findByfilename(number);
    }
}
